<div class="product-box">
<h3>Thông tin giỏ hàng của bạn</h3>
<?php if(empty($orders)) { ?>
	<div class="box s4 empty-cart">
		<?php echo __('Basket is empty', true); ?>
	</div>
<?php } else { ?>
	<?php echo $form->create(array('action'=>'index')); 
	?>
	<table class="table table-striped">
            <thead>
                <tr>
                    <th><?php echo __('#', true); ?></th>
                    <th><?php echo __('Product name', true); ?></th>
                    <th width="100"><?php echo __('Quantity', true); ?></th>
                    <th><?php echo __('Price', true); ?>(VNĐ)</th>
                    <th><?php echo __('Total', true); ?>(VNĐ)</th>
                    <th><?php echo __('Update', true); ?> </th>
                </tr>
            </thead>
            <tbody>
                <?php 
                    $i = 1;
                    $total = 0;
                    foreach($orders as $item) { 
				$sub_total = $item['price'] * $item['quantity'];
				$total += $sub_total;
		?>
                <tr>
                    <td><?php echo $i; ?></td>
                    <td><?php echo $item['name_'.$lang]; ?></td>
                    <td><input type="text" id="quantity<?php echo $item['id']; ?>" value="<?php echo $item['quantity']; ?>" size="3" class="input-mini"/></td>
                    <td><?php echo number_format($item['price'],0,' ','.'); ?></td>
                    <td>
                        <?php if (isset($vipDiscount)) : ?>
                            <?php echo number_format($sub_total,0,' ','.'); ?>
                        <?php else :
                            echo number_format($sub_total * (100-$vipDiscount)/100,0,' ','.');
                            endif;
                        ?>
                    </td>
                    <td><input value="<?php echo __('Update', true); ?>" type="button" onclick="run_update('update',<?php echo $item['id']; ?>);" />
					<input value="<?php echo __('Delete', true); ?>" type="button" onclick="run_update('delete',<?php echo $item['id']; ?>);" /> </td>
                </tr>
                <?php $i++;?>
                <?php } ?>
            </tbody>
            <tfoot>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td><strong><?php echo "Tổng cộng"; ?></td>
                    <td><strong><?php echo number_format($total,0,' ','.'); ?></strong></strong></td>
                    <td></td>
                </tr>
                
            </tfoot>
        </table>
	</div> 
	<div class="cleaner"></div>
	<div id="mydialog" style="display: hidden"></div>
	<div id="mua">
		<a href="<?php echo Router::url(array('controller' => 'order'));?>" style="padding-left:20px;"><?php echo __('Tiếp tục', true); ?></a>
	</div>
	</div>
	
	
	<script type="text/javascript">
		function run_update(action, id)
		{	
			var value =  $("input#quantity"+id).val();
			$("#mydialog").html('<?php echo __('Waiting to loading...', true); ?>');
			$.ajax({
				url: "<?php echo Router::url(array('action'=>'update')); ?>",
				type: 'post',
				data: {act:action, id:id, value:value },
				success: function(response) {
					$("#mydialog").html('<?php echo __('Updated done.', true); ?>');
					location.reload();
				}
			});
		}
		
	</script>
<?php } ?>
</div>